//
//  XMMineToolsView.m
//  XunMi
//
//  Created by MacBook on 2024/2/19.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMMineToolsView.h"

@interface XMMineToolsView ()
//@property (weak, nonatomic) IBOutlet UIButton *guardBtn;
@property (weak, nonatomic) IBOutlet UIButton *scoreBtn;
@property (weak, nonatomic) IBOutlet UIButton *goldBtn;
@property (weak, nonatomic) IBOutlet UIButton *bagBtn;
@end

@implementation XMMineToolsView

- (void)awakeFromNib {
    [super awakeFromNib];
//    self.guardBtn.titleLabel.numberOfLines = 0;
    self.scoreBtn.titleLabel.numberOfLines = 0;
    self.goldBtn.titleLabel.numberOfLines = 0;
    self.bagBtn.titleLabel.numberOfLines = 0;
//    [self.guardBtn setAttributedTitle:[self titleWithCount:@"99" type:@"守护"] forState:UIControlStateNormal];
    
    [self reload];
}

- (void)reload {
    [self.scoreBtn setAttributedTitle:[self titleWithCount:kUserModel.score_number type:@"积分"] forState:UIControlStateNormal];

    [self.goldBtn setAttributedTitle:[self titleWithCount:kStringFormat(@"%ld", kUserModel.golds.integerValue) type:@"金币"] forState:UIControlStateNormal];

    [self.bagBtn setAttributedTitle:[self titleWithCount:kStringFormat(@"%ld", kUserModel.coupons) type:@"卡包"] forState:UIControlStateNormal];
}

- (NSMutableAttributedString *)titleWithCount:(NSString *)count type:(NSString *)type {
    NSString *str = [NSString stringWithFormat:@"%@\n%@",count, type];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:3];
    [paragraphStyle setAlignment:NSTextAlignmentCenter];
    [attr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [str length])];

    [attr addAttributes:@{NSForegroundColorAttributeName: k1F1F1F, NSFontAttributeName: kUIFontBold(21)} range:[str rangeOfString:count]];
    
    [attr addAttributes:@{NSForegroundColorAttributeName: kHEX(@"#878787"), NSFontAttributeName: kUIFont(14)} range:[str rangeOfString:type]];
    return attr;
}

- (IBAction)act:(UIButton *)sender {
    if (self.clickBlock) {
        self.clickBlock(sender.tag);
    }
}

@end
